package com.sh.doctors.cloud.patient.view

import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.helper.extens.bindLifeCycle
import com.sh.doctors.cloud.R
import com.sh.doctors.cloud.databinding.ActivityAriticleListBinding
import com.sh.doctors.cloud.patient.viewmodel.AriticleModel
import com.base.view.BaseActivity
import io.ditclear.bindingadapter.SingleTypeAdapter
import me.jessyan.autosize.utils.LogUtils
import org.koin.android.viewmodel.ext.android.viewModel

class AriticleListActivity : BaseActivity<ActivityAriticleListBinding>() {
    private val mViewModel by viewModel<AriticleModel>()

    private val mNewsAdapter by lazy {
        SingleTypeAdapter(mContext, R.layout.patient_home_news_list_item, mViewModel.newsList)
    }

    override fun initView() {
        mBinding.vm = mViewModel
        mBinding.newsRv.apply {
            adapter = mNewsAdapter
            layoutManager = LinearLayoutManager(mContext, RecyclerView.VERTICAL, false)
        }
    }


    override fun getLayoutId(): Int = R.layout.activity_ariticle_list

    override fun loadData(isRefresh: Boolean) {
        mViewModel.getAriticle()
            .doOnSubscribe { showLoading() }.doAfterTerminate { hideLoading()

            }.bindLifeCycle(this).subscribe()

        mViewModel.getLocalAriticle().bindLifeCycle(this).subscribe()
    }

}
